#ifndef CUSTOMMESSAGEBOX_H
#define CUSTOMMESSAGEBOX_H

#include <QDialog>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFrame>
#include <QGraphicsDropShadowEffect>

class CustomMessageBox : public QDialog
{
    Q_OBJECT

public:
    enum IconType {
        NoIcon,
        Information,
        Warning,
        Critical,
        Question
    };

    enum ButtonType {
        Ok = 0x00000400,
        Cancel = 0x00400000,
        Yes = 0x00004000,
        No = 0x00010000,
        Close = 0x00000200
    };

    explicit CustomMessageBox(QWidget *parent = nullptr);
    ~CustomMessageBox();

    // 设置消息框内容
    void setTitle(const QString &title);
    void setText(const QString &text);
    void setIcon(IconType icon);
    void setButtons(int buttons);
    void setDefaultButton(ButtonType button);

    // 静态方法，方便使用
    static int information(QWidget *parent, const QString &title, const QString &text);
    static int warning(QWidget *parent, const QString &title, const QString &text);
    static int critical(QWidget *parent, const QString &title, const QString &text);
    static int question(QWidget *parent, const QString &title, const QString &text);
    static int question(QWidget *parent, const QString &title, const QString &text, 
                       ButtonType yesButton, ButtonType noButton);

signals:
    void buttonClicked(ButtonType button);

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private slots:
    void onButtonClicked();

private:
    void setupUI();
    void setupConnections();
    void updateButtonLayout();
    QString getIconText(IconType icon) const;
    QColor getIconColor(IconType icon) const;

private:
    QFrame *m_mainFrame;
    QVBoxLayout *m_mainLayout;
    QHBoxLayout *m_buttonLayout;
    
    QLabel *m_titleLabel;
    QLabel *m_textLabel;
    
    QPushButton *m_okButton;
    QPushButton *m_cancelButton;
    QPushButton *m_yesButton;
    QPushButton *m_noButton;
    QPushButton *m_closeButton;
    
    IconType m_iconType;
    int m_buttons;
    ButtonType m_defaultButton;
    
    // 拖拽相关
    bool m_dragging;
    QPoint m_dragStartPosition;
};

#endif // CUSTOMMESSAGEBOX_H
